#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
 
int gval = 100;
 
int main(int argc, char *argv[], char *env[])
{
        pid_t id = fork();
        if (id == 0)
        {
                while(1)
                {
                        printf("子进程: gval: %d, &gval: %p, pid: %d, ppid: %d\n", gval, &gval, getpid(), getppid());
                        sleep(1);
                        gval++;
                }
        }
        else
        {
                while(1)
                {
                        printf("父进程: gval: %d, &gval: %p, pid: %d, ppid: %d\n", gval, &gval, getpid(), getppid());
                        sleep(1);
                }
        }
        return 0;
}